<template>
  <el-container class="license-warp">
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      selectionType="multiple"
      :datakey="'rows'"
      :onColumnsChange="columns => this.columns = columns"
      :onRowSelectChange="arr => this.onChangeColumn = arr"
      :isColumnFilter="false"
    ></FilterTable>
    <div class="footer">
      <el-button @click="saveDialog" type="primary" :loading="addBtnState">确 定</el-button>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </el-container>
</template>
<script>
import { insuranceType } from '@/api/derived/insurance/insurancePolicy';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'Insure',
  props: [''],
  mixins: [dictionary],

  data() {
    return {
      addBtnState: null,
      fetchApi: insuranceType,
      fetchParams: { xhrAbort: false },
      columns: this.createTableColumns(),
      onChangeColumn: []
    };
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '保险代码',
          dataIndex: 'INSURANCE_TYPE_CODE',
          sorter: true
        },
        {
          title: '保险名称',
          dataIndex: 'INSURANCE_TYPE_NAME',
          sorter: true,
          showOverflowTooltip: true,
        },
        {
          title: '是否交强险',
          dataIndex: 'IS_COM_INSURANCE',
          sorter: true,     
          render: props => {
            return <span>{this.createDictText(props.row.IS_COM_INSURANCE, '1004')}</span>;
          }
        },
        {
          title: '险种类型',
          dataIndex: 'INSURANCE_TYPE_LEVEL',
          hidden:true   
        },
        //默认给父组件传值
        {
          title: '应收金额',
          dataIndex: 'RECEIVABLE_AMOUNT',
          hidden:true   
        },
        {
          title: '是否赠送',
          dataIndex: 'IS_PRESENTED',
          hidden:true   
        },
        

        
      ];
    },
    formChangeHandle() {},

    closeDialog() {
      this.$emit('closeDialog', false);
    },
    saveDialog() {
     //根据是否是交强险给险种类型赋值操作
      this.onChangeColumn.forEach(x=>{
          x.RECEIVABLE_AMOUNT=0;
          x.IS_PRESENTED=10041002;
         if(x.IS_COM_INSURANCE==10041002){
             x.INSURANCE_TYPE_LEVEL=10471002;
         }else if(x.IS_COM_INSURANCE==10041001){
             x.INSURANCE_TYPE_LEVEL=10471001;
         }
      });
      this.$emit('saveDialog', this.onChangeColumn);
    }
  },
  mounted() {}
};
</script>
<style lang="less" scoped>
.license-warp {
  flex-direction: column;

  .top {
    width: 100%;
    display: flex;
    flex-direction: column;

    .el-row {
      text-align: center;
    }
  }

  .footer {
    text-align: center;
  }
}
</style>
